export default class GameOver extends Sprite {

  constructor() {
    super();

    this.bg = null;
    this.txt = null;
    
    this.init();
  }

  init() {

    this.width = Config.deviceWidth;
    this.height = Config.deviceHeight;

    //黑色背景
    this.bg = new Sprite();
    this.bg.alpha = 0.8;
    this.bg.graphics.drawRect(0, 0, Config.deviceWidth, Config.deviceHeight, "#000000");
    this.addChild(this.bg);

    //loading文本
    this.txt = new Text();
    this.txt.color = "#FFFFFF";
    this.txt.fontSize = 30;
    this.txt.text = "GameOver\n\nClick Again";
    this.txt.width = Config.deviceWidth;
    this.txt.align = "center";
    this.addChild(this.txt);
  }

  setScore(score) {
		const _score = localStorage.getItem('runGameScore');
		if(_score && +_score > score){
			score = _score;
    }

		localStorage.setItem('runGameScore', score);
		this.txt.text = "GameOver\n\n Click Again\n\n Best Score : " + score;
		this.txt.y = (Config.deviceHeight - this.txt.height) * 0.5;
	}
}